/**
 * Project Name:excelutil
 * File Name:StringUtil.java
 * Package Name:com.lkx.util
 * Date:2017年6月7日上午9:47:06
 * Copyright (c) 2017~2020, likaixuan@test.com.cn All Rights Reserved.
 *
*/

package com.stylefeng.guns.modular.util;

import java.util.Collection;

import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.formula.functions.T;

/**
 * ClassName:StringUtil
 * Function: TODO ADD FUNCTION.
 * Reason: TODO ADD REASON.
 * Date:     2017年6月7日 上午9:47:06
 * @author   likaixuan
 * @version  V1.0
 * @since    JDK 1.7
 * @see
 */
public class StringUtil {
    /**
     * 首字母转小写
     *
     * @param s
     * @return
     */
    public static String toLowerCaseFirstOne(String s) {
        if (Character.isLowerCase(s.charAt(0))) {
            return s;
        } else {
            return (new StringBuilder())
                    .append(Character.toLowerCase(s.charAt(0)))
                    .append(s.substring(1)).toString();
        }
    }

    /**
     * 首字母转大写
     *
     * @param s
     * @return
     */
    public static String toUpperCaseFirstOne(String s) {
        if (Character.isUpperCase(s.charAt(0))) {
            return s;
        } else {
            return (new StringBuilder())
                    .append(Character.toUpperCase(s.charAt(0)))
                    .append(s.substring(1)).toString();
        }
    }

    /**
     * replace:(替换字符串函数)
     * 
     * @param strSource
     *            源字符串
     * @param strFrom
     *            要替换的子串
     * @param strTo
     *            替换为的字符串
     * @return
     * @since JDK 1.7
     */
    public static String replace(String strSource, String strFrom,
            String strTo) {
        // 如果要替换的子串为空，则直接返回源串
        if (strFrom == null || strFrom.equals(""))
            return strSource;
        String strDest = "";
        // 要替换的子串长度
        int intFromLen = strFrom.length();
        int intPos;
        // 循环替换字符串
        while ((intPos = strSource.indexOf(strFrom)) != -1) {
            // 获取匹配字符串的左边子串
            strDest = strDest + strSource.substring(0, intPos);
            // 加上替换后的子串
            strDest = strDest + strTo;
            // 修改源串为匹配子串后的子串
            strSource = strSource.substring(intPos + intFromLen);
        }
        // 加上没有匹配的子串
        strDest = strDest + strSource;
        // 返回
        return strDest;
    }
    
    
    public static String concat(String ... strArray){
    	StringBuilder sb=new StringBuilder();
    	for(String str : strArray){
    		sb.append(str+",");
    	}
    	return sb.toString().substring(0, sb.toString().length()-1);
    }
    
    public static String concat(Collection<String> objList){
    	StringBuilder sb=new StringBuilder();
    	for(String str : objList){
    		sb.append(str+",");
    	}
    	return sb.toString().substring(0, sb.toString().length()-1);
    }
    
    public static String nullToDefault(Object value, String defaultValue) {
		if (value == null) {
			return defaultValue;
		}
		return value.toString();
	}
    
    
    public static String ifNullOrEmptyDefault(String value,String defaultValye){
    	return value==null||value.trim().equals("null")?defaultValye:value;
    }
    
//    public static void main(String[] args){
//    	String value=null;
//    	System.out.println(StringUtil.ifNullOrEmptyDefault(value, 10000+""));
//    }
}

